package com.patzn.osgi.email.reg;

import com.patzn.osgi.email.api.IEmailService;
import com.patzn.osgi.email.factory.EmailServiceFactory;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

import java.util.Dictionary;
import java.util.Hashtable;

public class RegActivator implements BundleActivator {

    private ServiceRegistration<IEmailService> serviceRegistration;

    @Override
    public void start(BundleContext bundleContext) throws Exception {
        Dictionary<String, Object> properties = new Hashtable<>();
        properties.put("vendor", "163");
        serviceRegistration = bundleContext.registerService(IEmailService.class, new EmailServiceFactory(), properties);
    }

    @Override
    public void stop(BundleContext bundleContext) throws Exception {
        serviceRegistration.unregister();
    }
}
